<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:60:"D:\phpStudy\WWW\auth/application/web\view\show\agioview.html";i:1496201816;}*/ ?>
 
<link rel="shortcut icon" href="favicon.ico">
<link href="__CSS__/bootstrap.min.css" rel="stylesheet">
<link href="__CSS__/font-awesome.min.css" rel="stylesheet">
<link href="__CSS__/animate.min.css" rel="stylesheet">
<link href="__CSS__/style.min.css" rel="stylesheet">
<link href="__CSS__/admin.css" rel="stylesheet">
<div class="ibox float-e-margins">
	<div class="ibox-content form-horizontal">
		<!--商品栏目设置-->
		<div class="form-group">
			<label class="col-sm-3 control-label">店铺当前积分余额：</label>
			<div class="input-group col-sm-4">
				<label class="col-sm-3 control-label" style="margin-left: -10px;text-align: left;"><?php echo $score; ?></label>
				<button class="btn cz"><i class="fa fa-save"></i> 充值</button>
			</div>
		</div>
		
		<div class="form-group" style="display:none;">
			<label class="col-sm-3 control-label" >积分抵扣比例：</label>
			<div class="input-group col-sm-4">
				<input type="text" id="agio_zk" name="agio_zk" value="<?php echo $agiogood['agio_zk']; ?>" class="form-control" />
				<label class="col-sm-3 control-label" style="position: absolute;text-align: left;">%</label>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">购买商品该需要现金：</label>
			<div class="input-group col-sm-4">
				<input  type="hidden" id="sale_price" value="<?php echo $agiogood['sale_price']; ?>" >
				<input style="width: 40%;" type="text" id="agioneed_money" name="agioneed_money" value="0" class="form-control" onkeyup="this.value=this.value.replace(/[^\d]/g,'') " onafterpaste="this.value=this.value.replace(/[^\d]/g,'') "/>
				<lable style="width: 20%;    padding-right: 0px; padding-left: 0px;font-weight: bold;" class="col-sm-3 control-label">+&nbsp;积分：</lable>
				<input style="width: 40%;" type="text" id="agioneed_score" name="agioneed_score" value="<?php echo $agiogood['sale_price']; ?>" class="form-control" onkeyup="this.value=this.value.replace(/[^\d]/g,'') " onafterpaste="this.value=this.value.replace(/[^\d]/g,'') "/>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">上架数量：</label>
			<div class="input-group col-sm-4">
				<input type="text" id="agio_num" name="agio_num" value="<?php echo $agiogood['agio_num']; ?>" class="form-control" onkeyup="this.value=this.value.replace(/[^\d]/g,'') " onafterpaste="this.value=this.value.replace(/[^\d]/g,'') "/>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">状态：</label>
			<div class="input-group col-sm-4" id="agio_status">
			<input type="radio" name="is_agio" id="is_agio" value="0" <?php if($agiogood['is_agio']==0): ?> {php echo checked="true"} <?php endif; ?>/> 关闭
			&nbsp;
			<input type="radio" name="is_agio" id="is_agio" value="1" <?php if($agiogood['is_agio']==1): ?> {php echo checked="true"} <?php endif; ?>/> 开启
			</div>
		</div>
		<!--商品栏目设置end-->
		
		
		<div class="form-group">
			<div class="col-sm-4 col-sm-offset-8" style="text-align: right;">
				<button class="btn btn-info"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;
				<span onclick="wclose()"><a class="btn btn-danger"><i class="fa fa-arrow-left"></i> 返回 </a></span>
			</div>
		</div>
	</div>
</div>
 
<script src="__JS__/jquery.min.js"></script>
<script src="__JS__/bootstrap.min.js"></script>
<script src="__JS__/jquery.metisMenu.js"></script>
<script src="__JS__/jquery.slimscroll.min.js"></script>
<script src="__LIB__/layer/layer.js"></script>
<script>
	function wclose(){
    	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引  
        parent.layer.close(index);  
	}
	$(".cz").click(function(){
		parent.layer.closeAll();
		parent.window.location.href="../agent/exchange.html?type=1";//<?php echo url('',array('type'=>1)); ?>
		//location.href="../agent/recharge.html";
	});
	$(".btn-info").click(function(){
		var id = '<?php echo $id; ?>';
    	var agio_name = $("#agio_name").val();
    	/*if(!agio_name){	    	
    		layer.msg("请输入商品名称");
    		return;
    	}*/
    	var agio_zk = $("#agio_zk").val();
    	if(!agio_zk){	    	
    		layer.msg("请输入折扣比例");
    		return;
    	}
    	var money=$('#agioneed_money').val();//输入的价钱
			var sale2=$('#sale_price').val()*0.9;
			if(money>=sale2){
				layer.msg("金额不要超过售价的90%以上");
				return;
			}
		var agio_num=$("#agio_num").val();
		if(!agio_num||agio_num==0){	    	
    		layer.msg("请输入上架数量");
    		return;
    	}
    	$.ajax({
            type:"POST",
            url:"saveagio",
			data:{id:id,agio_name:$("#agio_name").val(),agioneed_money:$("#agioneed_money").val(),agio_zk:$("#agio_zk").val(),agioneed_score:$("#agioneed_score").val(),is_agio:$('#agio_status input[name="is_agio"]:checked').val(),agio_num:$("#agio_num").val()},
            success:function(data){
				layer.msg(data.msg, {
				  icon: 1,
				  time: 1000 //2秒关闭（如果不配置，默认是3秒）
				}, function(){
					if(data.code == 200) {
						parent.layer.closeAll();
   						parent.window.location.reload();
   					}
				}); 
            }
		});		
    });
    $("#agioneed_money").keyup(
    	function(){
    		var money=$('#agioneed_money').val();//输入的价钱
    		var sale=$('#sale_price').val();//销售价
    		var bl=sale-money;
    		$("#agioneed_score").val(bl);//积分bl>sale*10%
	    	//判断积分是否大于销售价的10%
			var sale2=$('#sale_price').val()*0.9;
			if(money>=sale2){
				layer.msg("金额不要超过售价的90%以上");
				return;
			}
    	}
    );
</script>
